/**
 * Show the width of the first splitpane on event changes.
 * @param {goog.events.Event} e The event
 */
var showWidth_ = function(e) {
	// alert(e.target.getFirstComponentSize());
	// var el = document.getElementById('componentOneWidth');
	// if (el) {
	// goog.dom.setTextContent(el, e.target.getFirstComponentSize());
	// }
}
var lhs = new goog.ui.Component();
var rhs = new goog.ui.Component();

// Set up splitpane with already existing DOM.
var splitpane1 = new goog.ui.SplitPane(lhs, rhs, goog.ui.SplitPane.Orientation.HORIZONTAL);

// Listen for change events and call showWidth.
goog.events.listen(splitpane1, goog.ui.Component.EventType.CHANGE, showWidth_);

splitpane1.setInitialSize(150);
splitpane1.setHandleSize(0);
splitpane1.decorate(document.getElementById('anotherSplitter'));
// splitpane1.setSize(new goog.math.Size(800, 300));splitpane1.setSize(new goog.math.Size(document.width - 10, document.height));

/**
 * Change the left splitter size or size a split pane.
 * This method reads the form fields to choose the splitter
 * and get the new values.
 */
var updatePane_ = function() {
	var componentSizeValue = document.getElementById('firstComponentSize').value;
	var width = document.getElementById('newWidth').value;
	var height = document.getElementById('newHeight').value;
	var s1Checked = document.getElementById('select1').checked;
	// Which splitter to update.
	var whichSplitter = (s1Checked) ? splitpane1 : splitpane2;

	var componentSize;
	if ('' != componentSizeValue) {
		componentSize = parseInt(componentSizeValue, 10);
	} else {
		componentSize = whichSplitter.getFirstComponentSize();
	}
	whichSplitter.setFirstComponentSize(componentSize);
	whichSplitter.setSize(new goog.math.Size(width, height));

	// If the first pane height is changed, force the second one to update
	// so it moves up or down the page.
	splitpane2.setFirstComponentSize();
}
/**
 * Change the orientation of the splitter pane.
 */
var changeOrientation_ = function() {
	var s1Checked = document.getElementById('select1').checked;
	// Which splitter to update.
	var whichSplitter = s1Checked ? splitpane1 : splitpane2;
	var orientation = whichSplitter.getOrientation();
	if (orientation == goog.ui.SplitPane.Orientation.VERTICAL) {
		whichSplitter.setOrientation(goog.ui.SplitPane.Orientation.HORIZONTAL);
	} else {
		whichSplitter.setOrientation(goog.ui.SplitPane.Orientation.VERTICAL);
	}
}
function onresize() {

	splitpane1.setSize(new goog.math.Size(document.width - 10, document.height));
}

////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
var $ = goog.dom.getElement;
var tree, clipboardNode;

// var divConsole = new goog.debug.DivConsole($('div-console'));// divConsole.setCapturing(true);
// var logger = goog.debug.LogManager.getRoot();

function makeTree() {
	// goog.debug.Trace.initCurrentTrace();
	// var tracerId = goog.debug.Trace.startTracer('makeTree');
	var treeConfig = goog.ui.tree.TreeControl.defaultConfig;
	treeConfig['cleardotPath'] = '../../images/tree/cleardot.gif';
	tree = new goog.ui.tree.TreeControl('root', treeConfig);

	createTreeFromTestData(tree, testData);

	tree.render($('treeContainer'));

	// var elapsed = goog.debug.Trace.stopTracer(tracerId);
	// logger.info('Trace:\n' + goog.debug.Trace.getFormattedTrace());
}
function createTreeFromTestData(node, data) {
	node.setHtml(data[0]);
	if (data.length > 1) {
		var children = data[1];
		var childNotCollapsible = 3;
		// Hard coded to reduce randomness.
		for (var i = 0; i < children.length; i++) {
			var child = children[i];
			var childNode = node.getTree().createNode('');

			node.add(childNode);
			createTreeFromTestData(childNode, child);

			if (i == childNotCollapsible && child.length > 1) {
				childNode.setIsUserCollapsible(false);
				childNode.setExpanded(true);
				nonCollapseNode = childNode;
			}

		}
	}
}
/*

function toggleNonCollapseNode() {
	nonCollapseNode.setIsUserCollapsible(!nonCollapseNode.isUserCollapsible());

}

function cut() {
	if (tree.getSelectedItem()) {
		clipboardNode = tree.getSelectedItem();
		if (clipboardNode.getParent()) {
			clipboardNode.getParent().remove(clipboardNode);
		}
	}
}

function paste() {
	if (tree.getSelectedItem() && clipboardNode) {
		tree.getSelectedItem().add(clipboardNode);
		clipboardNode = null;
	}
}
*/
makeTree();

////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
function showSize() {

	var s = "网页可见区域宽：" + document.body.clientWidth;
	s += "\r\n网页可见区域高：" + document.body.clientHeight;
	s += "\r\n网页可见区域高：" + document.body.offsetWeight + "   (包括边线的宽)";
	s += "\r\n网页可见区域高：" + document.body.offsetHeight + "   (包括边线的宽)";
	s += "\r\n网页正文全文宽：" + document.body.scrollWidth;
	s += "\r\n网页正文全文高：" + document.body.scrollHeight;
	s += "\r\n网页被卷去的高：" + document.body.scrollTop;
	s += "\r\n网页被卷去的左：" + document.body.scrollLeft;
	s += "\r\n网页正文部分上：" + window.screenTop;
	s += "\r\n网页正文部分左：" + window.screenLeft;
	s += "\r\n屏幕分辨率的高：" + window.screen.height;
	s += "\r\n屏幕分辨率的宽：" + window.screen.width;
	s += "\r\n屏幕可用工作区高度：" + window.screen.availHeight;
	s += "\r\n屏幕可用工作区宽度：" + window.screen.availWidth;
	alert(s);
}